package com.iot08.api.service;

import com.iot08.api.service.sms.IProviderJdySmsService;
import com.jdcloud.sdk.service.sms.client.SmsClient;
import com.jdcloud.sdk.service.sms.model.BatchSendRequest;
import com.jdcloud.sdk.service.sms.model.BatchSendResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author cwj
 * @description
 * @date 2025/6/3 14:12
 **/
@Service
@Slf4j
public class JdyunSmsService implements IProviderJdySmsService {

    // 地域信息不用修改
    private static String region = "cn-north-1";
    private final SmsClient smsClient;

    public JdyunSmsService(SmsClient smsClient){
        this.smsClient = smsClient;
    }

    /**
     * @description 发送短信
     * @author cwj
     * @param [phoneList, params, configMap]
     * @return com.jdcloud.sdk.service.sms.model.BatchSendResponse
     * @date @time 2025/6/3 14:33
     **/
    @Override
    public BatchSendResponse send(List<String> phoneList, List<String> params, Map<String, String> configMap) {
        log.info("短信发送签名：{}，短信发送模板{}", configMap.get("signId"), configMap.get("templateId"));
        BatchSendRequest request = new BatchSendRequest();
        request.setRegionId(region);
        request.setTemplateId(configMap.get("templateId"));
        request.setSignId(configMap.get("signId"));
        request.setPhoneList(phoneList);
        request.setParams(params);
        BatchSendResponse response = smsClient.batchSend(request);
        //log.info("京东云短信平台响应体: {}" , JSON.toJSONString(response));
        return response;
    }
}
